package com.yzh.controller;

import com.yzh.domain.LoginUser;
import com.yzh.service.LoginUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@Api(tags = "登录接口")
@RequestMapping("/user")
public class LoginUserController {

    private LoginUserService loginUserService;
    @Autowired
    public void setLoginUserService(LoginUserService loginUserService) {
        this.loginUserService = loginUserService;
    }

    @RequestMapping("/login")
    @ApiOperation("在这里来判断一下")
    public String login(String username, String password, HttpSession session, Model model){
        LoginUser user = loginUserService.login(username,password);
        if(user != null){
            session.setAttribute("user", user);
            return "redirect:/classroom/clist";
        }
        model.addAttribute("msg", "账号或密码错误");
        return "login/Login";
    }

    @RequestMapping("/loginOut")
    @ApiOperation("权限不够，返回到登录页")
    public String logOut(HttpSession session){
        session.invalidate();
        return "redirect:/login/Login.html";
    }

}
